package com.kaizige.realtor.Controller;

import com.kaizige.realtor.Dao.messageDao;
import com.kaizige.realtor.Dao.recordDao;
import com.kaizige.realtor.Pojo.message;
import com.kaizige.realtor.Pojo.record;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

@Controller
public class seeHouseController {
	@Autowired
	recordDao rd;
	@Autowired
	messageDao md;
	@GetMapping("/tenSeeHou")
	public String toTenSeeHou(HttpSession session, Model model){
		List<Map<String, Object>> hisRecord = rd.getHisRecordByName((String)session.getAttribute("LoginUser"));
		List<Map<String, Object>> nowRecord = rd.getNowRecordByName((String)session.getAttribute("LoginUser"));
		model.addAttribute("hisRecord",hisRecord);
		model.addAttribute("nowRecord",nowRecord);
		return "/extraFunc/tenSeeHou";
	}
	
	@RequestMapping("/seeHouse/{id}")
	public String seeHouse(HttpSession session, @PathVariable("id")int id){
		String user = (String)session.getAttribute("LoginUser");
		record r = new record(user,id,0);
		rd.addRecord(r);
		return "redirect:/tenSeeHou";
	}
}
